<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				设置成员类型
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form :form="form">
					<a-form-item label="成员信息">{{ text.Name }} / {{ text.UserNo }}</a-form-item>
					<a-form-item label="类型">
						<a-radio-group v-decorator="['Type', { rules: [{ required: true, message: '请输选择类型' }] }]" name="radioGroup">
							<a-radio v-for="(item, i) in ActivityMemberTypeList" :key="i" :value="item.Key">{{ item.Value }}</a-radio>
						</a-radio-group>
					</a-form-item>
					<a-form-item class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ !currentID ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-item>
				</a-form>
			</div> 
		</div>
	</div>
</template>

<script>
import moment from 'moment';
import { ManageDoSetTypeActivityMember, UserDoSetTypeActivityMember,DoGetActivityMemberTypeListCommon } from '@/api/follow';
export default {
	props: {
		text: Object
	},
	watch: {
		text: function(text) {
			if (JSON.stringify(text) == '{}') {
				this.currentID = ''
			} else {
				let that = this;
				that.currentID = text.ID;
				setTimeout(function() {
					that.form.setFieldsValue({
						Type: text.Type,
					});
				}, 100);
			}
		}
	},
	data() {
		return {
			loading: false,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			currentID: '',
			ActivityMemberTypeList:[]
		};
	},
	created() {
		this.getOtherList()
	},
	methods: {
		moment,
		async getOtherList(){
			let res = await DoGetActivityMemberTypeListCommon();
			this.ActivityMemberTypeList = res.data.data;
		},
		closeFunction(data) {
			this.form.resetFields();
			this.$emit('closeFun', data);
		},
		handleSubmit(e) {
			this.form.validateFields(async (err, values) => {
				if (!err) {
					let data = {};
					data = values;
					let res = {};
					data.id = this.currentID;
					if (this.text.mytype=='user') {
						res = await UserDoSetTypeActivityMember(data);
					} else {
						res = await ManageDoSetTypeActivityMember(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
/deep/.ant-form-item {
	margin: 20px 50px;
	display: flex;
}
/deep/.ant-form-item-label {
	width: 100px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
/deep/.ant-calendar-picker {
	width: 100%!important;
}
</style>
